package com.net.xpay.admin.controller.admin;

import com.google.common.base.Preconditions;
import com.net.common.exception.BusinessException;
import com.net.common.model.ResultPagedList;
import com.net.xpay.common.domain.operator.OperatorUser;
import com.net.xpay.common.domain.operator.OperatorUserBindLog;
import com.net.xpay.common.manager.operator.OperatorUserBindLogManager;
import com.net.xpay.common.manager.operator.OperatorUserManager;
import com.net.xpay.core.constant.PoseidonErrorCode;
import com.net.xpay.core.model.OperatorUserBindLogSearchModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/operation-user-bind-log")
@Api(tags = "运营/多商户管理操作记录", description = "运营 多商户管理操作记录 ")
public class AdminOperatorUserBindLogController {

    @Autowired
    private OperatorUserManager operatorUserManager;

    @Autowired
    private OperatorUserBindLogManager operatorUserBindLogManager;


    @ApiOperation("搜索")
    @PostMapping("/search")
    @ResponseBody
    @PreAuthorize("hasAnyRole('ADMIN', 'operation-user-bind-log::search')")
    public ResultPagedList<OperatorUserBindLog> searchOperatorUserBindLog(@RequestBody OperatorUserBindLogSearchModel searchModel) {
        Preconditions.checkArgument(searchModel.getOperatorUserId() != null);
        OperatorUser operatorUser = operatorUserManager.getById(searchModel.getOperatorUserId());
        if (operatorUser == null){
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "用户不存在");
        }
        List<OperatorUserBindLog> records = operatorUserBindLogManager.search(searchModel);
        long count = operatorUserBindLogManager.searchCount(searchModel);

        return new ResultPagedList<>(records, count, searchModel);
    }




}
